/* 路由懒加载：当打包构建应用时，JavaScript包会变得非常大，影响页面加载。
(按需加载)如果把不同路由对应的组件分割成不同的代码块，当路由被访问时才加载对应组件，就会更加高效。 */
/* const foo=()=>{
    return import('@/pages/Home')
} */

//配置路由
export default [
    {
        //订单详情
        path: '/center',
        component: () => import('@/pages/Center'),
        meta: { show: true },
        children: [
            //二级路由
            {
                path: 'myorder',
                component: () => import('@/pages/Center/MyOrder')
            },
            {
                path: 'grouporder',
                component: () => import('@/pages/Center/GroupOrder')
            },
            //重定向:进入订单详情时，首先自动展示我的订单信息
            {
                path: '/center',
                redirect: '/center/myorder',
            }
        ]
    },
    {
        //微信支付成功的跳转路由
        path: '/paysuccess',
        component: () => import('@/pages/PaySuccess'),
        meta: { show: true },
        
    },
    {
        //支付的跳转路由
        path: '/pay',
        component: () => import('@/pages/Pay'),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //必须从shortcart来
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        //结算的跳转路由
        path: '/trade',
        component: () => import('@/pages/Trade'),
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //必须从shortcart来
            if (from.path == '/shopcart') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        //购物车的跳转路由
        path: '/shopcart',
        component: () => import('@/pages/ShopCart'),
        meta: { show: true }
    },
    {
        //加入购物车跳转路由
        path: '/addcartsuccess',
        component: () => import('@/pages/AddCartSuccess'),
        name: 'addcartsuccess',
        meta: { show: true }
    },
    {
        //路由跳转时带上id给详情页面
        path: '/detail/:skuId',
        component: () => import('@/pages/Detail'),
        meta: { show: true }
    },
    {
        path: '/home',
        component: () => import('@/pages/Home'),
        //给路由添加路由元信息，判断Footer显示/隐藏
        meta: { show: true }
    },
    {
        path: '/login',
        component: () => import('@/pages/Login'),
        meta: { show: false }
    },
    {
        path: '/register',
        component: () => import('@/pages/Register'),
        meta: { show: false }
    },
    {
        path: '/search/:keyWord?',//params参数需要：占位  ?可指定params参数可传可不传
        //path:'/search'  //query传参不需要：占位
        component: () => import('@/pages/Search'),
        meta: { show: true },
        name: 'search',
        //路由组件能不能传递props数据
        //布尔值方法：params
        //props:true,
        //对象写法：传递额外参数
        //props:{a:1,b:2},
        //函数写法:params参数、query参数都可以
        props: ($route) => {
            return { keyWord: $route.params.keyWord, K: $route.query.K }
        }

    },
    //重定向:打开浏览器时，首先访问首页home
    {
        path: '*',
        redirect: '/home',
        meta: { show: true }
    }
]

